package com.chenhao.springcloud.chenhaoseataaccount.service.impl;

import com.chenhao.springcloud.chenhaoseataaccount.mapper.AccountMapper;
import com.chenhao.springcloud.chenhaoseataaccount.service.AccountService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 *
 * 账户业务
 *
 * @return
 * @author chenhao
 *
 * @date 2020/5/15 11:33
 */
@Service
public class AccountServiceImpl implements AccountService {

    private static final Logger LOGGER = LoggerFactory.getLogger(AccountServiceImpl.class);
    @Autowired
    private AccountMapper accountMapper;

    /**
     * 扣减账户余额
     */
    @Override
    public void decrease(Long userId, BigDecimal money) {
        LOGGER.info("------->account-service中扣减账户余额开始");
        //模拟超时异常，全局事务回滚
   /*    try {
           Thread.sleep(30*1000);
       } catch (InterruptedException e) {
           e.printStackTrace();
       }*/
        accountMapper.decrease(userId,money);
        LOGGER.info("------->account-service中扣减账户余额结束");
    }
}
